package mju.cxf.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import mju.cxf.entity.Categories;
import mju.cxf.result.Result;
import mju.cxf.service.CategoriesService;
import mju.cxf.vo.CategoriesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类相关接口
 */

@RestController
@RequestMapping("/api/categories")
@Api(tags = "分类接口列表")
public class ICategoriesController {
    @Autowired
    private CategoriesService categoriesService;

    /**
     * U主页查询分类信息
     * @return 分页查询结果
     */
    @GetMapping("/channel")
    @ApiOperation(value = "主页的菜单信息",notes = "查询分类数据")
    public Result<List<Categories>> getUsersByChannel() {
        return Result.success(categoriesService.selectToChannel());
    }


    /**
     * U分页查询分类信息
     * @return 分页查询结果
     */
    @PostMapping("/pages")
    @ApiOperation(value = "分页查询分类",notes = "根据id和页码查询分类数据")
    public Page<CategoriesVO> getUsersByName(@RequestParam(value = "name",required = false) String name,
                                             @RequestParam(value = "type",required = false) Integer type,
                                             @RequestParam(value = "state",required = false) Integer state,
                                             @RequestParam(value = "current",defaultValue = "1") int current,
                                             @RequestParam(value = "size",defaultValue = "99") int size) {
        return categoriesService.selectPage(name, current, size, type, state);
    }
}
